package com.ruoyi.web.controller.system;

/**
 * @projectName: RuoYi-Vue
 * @package: com.ruoyi.web.controller.system
 * @className: ThirdPartLoginController
 * @author: sean
 * @description: TODO
 * @date: 2023/2/20 14:47
 * @version: 1.0
 */

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.ThirdLoginService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 第三方登录验证
 *
 * @author ruoyi
 */
@RestController
public class ThirdPartLoginController {
    /**
     * @Description: 平台带着token来系统里面登陆
     * 这边需要做两个步骤：
     * 1.检测数据库里面有没有这个用户名，没有提示用户不存在
     * 2.有则执行登陆操作
     * 平台没有这个token，则直接打回去，不让上来
     * @author: sean
     * @date: 2023/2/21 17:40
     * @version: 1.0
     */
    @Autowired
    private ThirdLoginService loginService;

    @Anonymous
    @PostMapping("/toThirdPartGetAuthJHaveToken")
    @ApiOperation(value = "平台带着token过来登录")
    public AjaxResult toThirdPartGetAuthJHaveToken(String token) {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌(免密登录)
        String tokenNew = loginService.thirdLogin(token);
        ajax.put(Constants.TOKEN, tokenNew);
        ajax.put("msg", "登录成功");
        return ajax;
    }
}
